var currentpage = 1;//当前页码
var pagesize = 4;//每页显示数据量
var totalCount = 0;//总条数
var sumpage = 1;//总页数
var flag = 0;//开关


function showInfo() {
    flag = 0
    //
    $.ajaxSettings.async = false;
    var names = [];    //类别数组（用于存放饼图的类别）
    var brower = [];

    var myChart = echarts.init(document.getElementById('main'), "dark");
    window.onresize = function () {
        myChart.resize();

    }
    myChart.setOption({
        backgroundColor: ['#F2F2F2'],
        tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },

        toolbox: {
            show: true,
            feature: {
                mark: {show: true},
                dataView: {show: true, readOnly: false},
                magicType: {
                    show: true,
                    type: ['pie', 'funnel'],
                    option: {
                        funnel: {
                            x: '50%',
                            width: '50%',
                            funnelAlign: 'left',
                            max: 1548
                        }
                    }
                },
                restore: {show: true},
                saveAsImage: {show: true}
            }
        },

        legend: {
            orient: 'vertical',
            x: 'left',
            data: [],
            itemWidth: 24, // 设置宽度
            itemHeight: 16, // 设置高度
            itemGap: 5, // 设置间距
            textStyle: {
                // 文字颜色
                color: '#000',
                // 字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
                fontWeight: '400',
                // 字体系列
                fontFamily: 'Source Han Sans CN',
                // 字体大小
                fontSize: 12,
                //行高
                lineHeight: 30
            }
        },
        calculable: true,
        series: [{
            name: '发布排行',
            type: 'pie',
            radius: '70%',
            center: ['50%', '60%'],
            data: [],
            label:{
                normal:{textStyle: {
                    color: '#000'
                    }}
            }
        }]
    });
    $("#table-page").find("tr:gt(1) td").html("&nbsp;");

    $.getJSON("bingtu", function (dataA) {
        $(dataA).each(function (i, v) {
            names.push(v.nian);    //挨个取出类别并填入类别数组
            brower.push({
                value: v.sum,
                name: v.nian
            });

            myChart.setOption({        //加载数据图表
                legend: {
                    data: names
                },
                series: [{
                    data: brower
                }]
            });
        })

    })
    let jsonA = {
        currentpage: currentpage,
        pagesize: pagesize
    }
    $.getJSON("showinfo", jsonA, function (data) {
        totalCount = data.total;
        sumpage = data.pages;

        $(data.list).each(function (i, v) {

            nian = v.nian;
            $("#table-page").find("tr").eq(i + 1).find("td").eq(0).text(v.nian);
            $("#table-page").find("tr").eq(i + 1).find("td").eq(1).text(v.sum);
            $("#table-page").find("tr").eq(i + 1).find("td").eq(1).text(v.sum);
            $("#table-page").find("tr").eq(i + 1).find("td").eq(2).text(v.doctor);
            $("#table-page").find("tr").eq(i + 1).find("td").eq(3).text(v.graduate);
            $("#table-page").find("tr").eq(i + 1).find("td").eq(4).text(v.regular);
            $("#table-page").find("tr").eq(i + 1).find("td").eq(5).text(v.junior);
        }, "json")
    })
    $.ajaxSettings.async = true;
    showPage()
}


function first() {
    currentpage = 1;
    showInfo()
}

function next() {
    currentpage = currentpage + 1;
    if (currentpage > sumpage) {
        currentpage = sumpage
    }
    showInfo()
    return;
}

function prv() {

    currentpage = currentpage - 1;
    if (currentpage < 1) {
        currentpage = 1
    }
    ;
    showInfo()
}

function last() {
    currentpage = sumpage;
    showInfo()
}

function showinfo() {
    showInfo()
}

function showPage() {

    if (sumpage == 0) {
        sumpage = 1;
    }
    if (currentpage < 1) {
        currentpage = 1
    }
    $(".showPage").text(currentpage + "/" + sumpage);
}









